import request from '@/utils/useRequest'
export const httpUpload = (file) => {
    let formData = new FormData()
    formData.append('file', file)
    return request({
        url: '/upload/file',
        method: 'post',
        data: formData
    })
}
const getApi = (api) => {
    return  {
        list: (data) => {
            return request({
                url: `/${api}/list`,
                params: data,
                method: 'get'
            })
        },
            page: (data) => {
            return request({
                url: `/${api}`,
                params: data,
                method: 'get'
            })
        },
            read: (id) => {
            return request({
                url: `/${api}/` + id,
                method: 'get'
            })
        },
            update: (data) => {
            return request({
                url: `/${api}/` + data.id,
                data,
                method: 'put'
            })
        },
            create: (data) => {
            return request({
                url: `/${api}`,
                data,
                method: 'post'
            })
        },
            del: (id) => {
            return request({
                url: `/${api}/` + id,
                method: 'delete'
            })
        },
    }
}
export const http = {
    Banner: {
        list: (data) => {
            return request({
                url: '/banner/list',
                params: data,
                method: 'get'
            })
        },
        page: (data) => {
            return request({
                url: '/banner',
                params: data,
                method: 'get'
            })
        },
        read: (id) => {
            return request({
                url: '/banner/' + id,
                method: 'get'
            })
        },
        update: (data) => {
            return request({
                url: '/banner/' + data.id,
                data,
                method: 'put'
            })
        },
        create: (data) => {
            return request({
                url: '/banner',
                data,
                method: 'post'
            })
        },
        del: (id) => {
            return request({
                url: '/banner/' + id,
                method: 'delete'
            })
        },
    },
    Category: {
        list: (data) => {
            return request({
                url: '/category/list',
                params: data,
                method: 'get'
            })
        },
        page: (data) => {
            return request({
                url: '/category',
                params: data,
                method: 'get'
            })
        },
        read: (id) => {
            return request({
                url: '/category/' + id,
                method: 'get'
            })
        },
        update: (data) => {
            return request({
                url: '/category/' + data.id,
                data,
                method: 'put'
            })
        },
        create: (data) => {
            return request({
                url: '/category',
                data,
                method: 'post'
            })
        },
        del: (id) => {
            return request({
                url: '/category/' + id,
                method: 'delete'
            })
        },
    },
    ProductList: {
        ...getApi('goods')
    },
    ProductOrder: {
        ...getApi('orderGoods')
    },
    ProductOrderDetail: {
        ...getApi('orderGoodsDetail')
    },
    GiftCategory: {
        ...getApi('categoryGift')
    },
    GiftList: {
        ...getApi('gift')
    },
    Member: {
        ...getApi('member')
    },
    MemberAddress: {
        ...getApi('address'),
        updateStatus: (data) => {
            return request({
                url: '/address/updateStatus',
                data,
                method: 'post'
            })
        }
    },
    GiftSend: {
        ...getApi('giftSend')
    },
    GiftSendItem: {
        ...getApi('giftSendItem'),
        readCode: (code) => {
            return request({
                url: '/giftSendItem/readCode/',
                method: 'get',
                params: {code}
            })
        }
    }
}